package mashuaiproject.mashuaiproject.controller;

import mashuaiproject.mashuaiproject.dto.OtherMesDto;
import mashuaiproject.mashuaiproject.dto.OtherParmDto;
import mashuaiproject.mashuaiproject.dto.QuesionUserDto;
import mashuaiproject.mashuaiproject.mapper.OnlieCoummtiyMapper;
import mashuaiproject.mashuaiproject.model.Quesions;
import mashuaiproject.mashuaiproject.model.Users;
import mashuaiproject.mashuaiproject.model.XunZhang;
import mashuaiproject.mashuaiproject.serivce.OtherSeivce;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

//其他人资料卡
@Controller
public class SelfOtherContrller {
    @Autowired
    private OtherSeivce otherSeivce;
    @Autowired
    private OnlieCoummtiyMapper onlieCoummtiyMapper;

    @GetMapping("/othermes/{userId}")
    public String otherMEs(@PathVariable(name = "userId")Integer userId, Model model,
                           @RequestParam(name = "staues",required = false,defaultValue = "boke")String staues,
                           HttpServletRequest request){
        //获取当前用户
        Users currentUser= (Users) request.getSession().getAttribute("user");
        //找出这个用户需要的信息
        //1.获取勋章
        List<XunZhang> xunZhangList=otherSeivce.selectUserSelfXunzhang(userId);
        //2:获取个人信息以及携带一些必要的信息
        OtherParmDto otherParmDto=otherSeivce.selectAllParm(userId,currentUser.getId());
        //3.获取个人博客信息
        List<Quesions> quesionsList=otherSeivce.selectOneQueisons(userId);
        //4.获取收藏的信息
        List<QuesionUserDto> saveQuesions=otherSeivce.selectSaveQuesion(userId);
        //5.获取关注信息
        List<Users> guanZhuUsers=otherSeivce.selectGuanzhuUsers(userId);
        //6.获取粉丝信息
        List<Users> fensiUsers=otherSeivce.selectfensiUsers(userId);

        //7.获取一些单独的属性

        //携带必备的数据
        model.addAttribute("users",otherParmDto);
        model.addAttribute("xunZhangList",xunZhangList);
        model.addAttribute("staues",staues);
        model.addAttribute("quesionsList",quesionsList);
        model.addAttribute("saveQuesions",saveQuesions);
        model.addAttribute("guanZhuUsers",guanZhuUsers);
        model.addAttribute("fensiUsers",fensiUsers);
        //判断是否已经加过该好友（当用户--》生擒滚动用户）
        //判断两个人是否已经是好友
        Integer checkIsFriedns=onlieCoummtiyMapper.checkIsShenqing(currentUser.getId(),userId);
        System.err.println("checkIsFriedns："+checkIsFriedns);
        if(checkIsFriedns!=0){
            //已经申请过---判断是好友还是未审核
            Integer checkIsAgree=onlieCoummtiyMapper.checkIsAgree(currentUser.getId(),userId);
            if(checkIsAgree!=0){
                //已经同意
                model.addAttribute("isFriednds","yes");
                model.addAttribute("showMess","已是好友");
            }
        }else {
            model.addAttribute("isFriednds","no");
            model.addAttribute("showMess","添加好友");
        }

        return "other";
    }

    @ResponseBody
    @GetMapping("/updateChengWei")
    public String  updateChengWei(@RequestParam("xunzhangId")Integer xunzhangId,
                                             @RequestParam("currentUserId")Integer currentUserId){
        //根据选择的勋章更新称号(返回当前的称哈即可)
        String  upateCW=otherSeivce.updateChengWei(currentUserId,xunzhangId);

        return upateCW;
    }

}
